/*

Miranda IM: the free IM client for Microsoft* Windows*

Copyright 2000-2007 Miranda ICQ/IM project, 
all portions of this codebase are copyrighted to the people 
listed in contributors.txt.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
aLONG with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/
#ifndef _SVC_CONTACTS_INCLUDED_
#define _SVC_CONTACTS_INCLUDED_ 1

/***********************************************************************************************************
 * some definitions
 ***********************************************************************************************************/
#define MAX_DESC	50

#if defined( _UNICODE )
 #define DBVT_TCHAR	DBVT_WCHAR
#else
 #define DBVT_TCHAR	DBVT_ASCIIZ
#endif

/***********************************************************************************************************
 * typedefs
 ***********************************************************************************************************/
typedef struct TEnumListItem {
	LPCSTR			pszName;
	TEnumListItem	*next;
} ENUMLISTITEM, *LPENUMLISTITEM;

typedef struct TEnumList{
	LPENUMLISTITEM first;
	LPENUMLISTITEM last;
} ENUMLIST, *LPENUMLIST;

/***********************************************************************************************************
 * some macros to make the world easier
 ***********************************************************************************************************/
#define	DBGetSetting			DBGetSettingAS
#define	DBGetSettingDword		DBGetContactSettingDword
#define	DBGetSettingRangedByte	DBGetContactSettingRangedByte
#define	DBGetSettingRangedDword	DBGetContactSettingRangedDword

#define DBGetByte(szSetting, bDefault)	DBGetSettingByte(NULL, MODNAME, (LPCSTR)(szSetting), (BYTE)(bDefault))

#define	DBGetContactDisplayName(hContact)	((LPTSTR)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)(hContact), GCDNF_TCHAR))
#define DBGetContactBaseProto(hContact)		((LPCSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)(hContact), NULL))

/***********************************************************************************************************
 * the prototypes
 ***********************************************************************************************************/

// basic routines
BYTE	DBGetSettingByte(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, BYTE errorValue);
WORD	DBGetSettingWord(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, WORD errorValue);
INT		DBGetSettingStr(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *pdbv);
INT		DBGetSettingAS(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *pdbv);
INT		DBGetSettingTS(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *pdbv);
INT		DBGetSettingUtf8(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *pdbv);

// extended abilities
WORD 	DBGetSettingCtrlUnicode(HANDLE hContact, LPCSTR szModule, LPCSTR szSubModule, LPCSTR szBaseProto, LPCSTR szSetting, DBVARIANT* dbv);
INT		DBGetSettingStaticString(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting, LPSTR szValue, INT cchValue);
INT		DBGetSettingEx(HANDLE hContact, LPCSTR pszModule, LPCSTR pszBaseProto, LPCSTR pszSetting, DBVARIANT* pdbv);
INT 	DBGetSettingStrEx(HANDLE hContact, LPCSTR pszModule, LPCSTR pszBaseProto, LPCSTR pszSetting, DBVARIANT *pdbv);

BOOLEAN DBSettingExists(HANDLE hContact, LPCSTR szModule, LPCSTR szSetting);
INT		DBCopyModule(HANDLE hContactSrc, LPCSTR pszModuleSrc, HANDLE hContactDst, LPCSTR pszModuleDst, BOOLEAN bForceOverwrite);
VOID	DBDeleteModule(HANDLE hContact, LPCSTR pszModule);
VOID	DBDeleteSettingArray(HANDLE hContact, LPCSTR pszModule, LPCSTR pszFormat, INT iStart);

LPSTR	DBVariantToStringA(DBVARIANT *dbv, BOOLEAN bPrepentType = FALSE);
LPWSTR	DBVariantToStringW(DBVARIANT *dbv);
DWORD	WhenWasContactAdded(DWORD dwUIN, LPCSTR pszBaseProto);
BOOL	IsDuplicateEvent(HANDLE hContact, DBEVENTINFO dbei);
BOOLEAN IsMetaContactProtoWantToScan(LPCSTR pszProto);

INT		IsModuleEmpty(HANDLE hContact, LPCSTR szModule);
INT		DBEnumModules(LPENUMLIST pEnumList);
INT		DBEnumSettings(HANDLE hContact, LPCSTR pszModule, LPENUMLIST pEnumList);
VOID	DBFreeEnumList(LPENUMLIST pEnumList);

#endif /* _SVC_CONTACTS_INCLUDED_ */